﻿using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using BigBlueSparx.NetMF.FEZ.HMC6352Compass;
using BigBlueSparx.NetMF.FEZ;

namespace FEZ_Panda_Compass_Module_Test
{

    public class Program
    {
        public static void Main()
        {
            HMC6352Compass compass = new HMC6352Compass();
            float lastHeading = (int)compass.GetHeading();

            byte ver = compass.ReadEeprom(HMC6352Compass.EEPROMAddress.SoftwareVersion);
            Debug.Print("Software Version = " + ver.ToString());

            byte i2cAddr = compass.ReadEeprom(HMC6352Compass.EEPROMAddress.SlaveAddress);
            Debug.Print("Slave Address = " + i2cAddr.ToString());

            HMC6352Compass.OperationalMode mode = compass.GetOperationalMode();
            Debug.Print("Operational Mode = " + mode.ToString());

            HMC6352Compass.Frequency frequency = compass.GetFrequency();
            Debug.Print("Frequency = " + frequency.ToString());

            while (true)
            {
                Thread.Sleep(500);

                float heading = compass.GetHeading();
                if (heading != lastHeading)
                {
                    Debug.Print(heading.ToString());
                }
                lastHeading = heading;
                //Debug.Print(heading.ToString());
            }
        }

    }
}

//using System;
//using System.Threading;
//using Microsoft.SPOT;
//using GHIElectronics.NETMF.FEZ;

//public class Program
//{
//    public static void Main()
//    {
//        FEZ_Shields.KeypadLCD.Initialize();
//        FEZ_Shields.KeypadLCD.TurnBacklightOn();
//        int i = 0;
//        while (true)
//        {
//            FEZ_Shields.KeypadLCD.CursorHome();
//            FEZ_Shields.KeypadLCD.Print("Count " + i++);
//            FEZ_Shields.KeypadLCD.SetCursor(1, 9);
//            switch (FEZ_Shields.KeypadLCD.GetKey())
//            {
//                case FEZ_Shields.KeypadLCD.Keys.Up:
//                    FEZ_Shields.KeypadLCD.Print("Up     ");
//                    break;
//                case FEZ_Shields.KeypadLCD.Keys.Down:
//                    FEZ_Shields.KeypadLCD.Print("Down   ");
//                    break;
//                case FEZ_Shields.KeypadLCD.Keys.Left:
//                    FEZ_Shields.KeypadLCD.Print("Left   ");
//                    break;
//                case FEZ_Shields.KeypadLCD.Keys.Right:
//                    FEZ_Shields.KeypadLCD.Print("Right  ");
//                    break;
//                case FEZ_Shields.KeypadLCD.Keys.Select:
//                    FEZ_Shields.KeypadLCD.Print("Select ");
//                    break;
//                case FEZ_Shields.KeypadLCD.Keys.Special1:
//                    FEZ_Shields.KeypadLCD.Print("       ");
//                    break;
//                case FEZ_Shields.KeypadLCD.Keys.Special2:
//                    FEZ_Shields.KeypadLCD.Print("Nope...");
//                    break;
//            }
//            Thread.Sleep(500);
//        }
//    }
//}